package com.spzx.payment.controller;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.rabbitmq.service.RabbitmqService;
import com.spzx.order.api.RemoteOrderService;
import com.spzx.order.domain.OrderInfo;
import com.spzx.payment.config.AlipayConfig;
import com.spzx.payment.domain.PaymentInfo;
import com.spzx.payment.service.IPaymentInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

@RestController
@Tag(name = "支付宝支付模块")
@Slf4j
@RequestMapping("/alipay")
public class AlipayController extends BaseController {

    @Resource
    IPaymentInfoService paymentInfoService;

    ///submitAlipay/23232bd2-665c-4490-94a3-ebb2da4f68
    @GetMapping("/submitAlipay/{orderNo}")
    @Operation(summary = "支付宝支付接口：跳转到支付宝支付页")
    public AjaxResult submitAlipay(@PathVariable("orderNo") String orderNo) {
      return success(paymentInfoService.submitAlipay(orderNo));
    }
    //同步回调地址： 浏览器主动访问
    //http://商户网关地址/alipay.trade.wap.pay-JAVA-UTF-8/return_url.jsp



    //异步回调接口： 接收支付宝传入的用户支付结果！！
    //  http://y6xt9r.natappfree.cc/alipay/notifyUrl     //服务器地址必须使用spzx-payment的 不能使用网关，因为该接口是支付宝来调用！！
    @Operation(summary = "支付宝异步回调接口：接收用户支付结果 更新订单状态")
    @PostMapping("notifyUrl")
    public String notifyUrl(@RequestParam Map<String,String> params){//接收支付宝传入的用户支付的结果！！
        return paymentInfoService.notifyUrl(params);
    }

}
